<template>
  <div class="loginIndex">
    <el-form ref="form" :model="form" label-width="80px" width="30%">
      <el-form-item label="用户名">
        <el-input v-model="form.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-button type="primary" @click="login">登 录</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "admin",
      password: "123456",
      form: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      if (
        this.form.username === this.username &&
        this.form.password === this.password
      ) {
        this.$message({
          type: "success",
          message: "登录成功!",
        });
        this.$router.push("/");
      }else{
          this.$message({
          type: "error",
          message: "用户名或密码错误，请重新输入!",
        });
          this.form.username ="";
          this.form.password ="";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.loginIndex {
  background-color: orange;
  width: 100vw;
  height: 100vh;
}
.el-input {
  width: 250px;
}
.el-form {
  padding-top: 80px;
}
.el-form-item {
  width: 340px;
  margin: 0 auto 22px;
}
</style>